package com.chentf.rabbitmq.workquene03;

import com.chentf.rabbitmq.utils.RabbitMqUtilsSGG;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;
import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
import sun.nio.cs.FastCharsetProvider;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * 消息在手动应答时是不丢失、放回队列中重新消费
 */
public class Task2 {

    private final static String QUEUE_NAME = "hello";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMqUtilsSGG.getChannel();
        //声明队列
        //持久化 需要让Queue持久化
        boolean durable = true;
        channel.queueDeclare(QUEUE_NAME, durable,false,false,null);
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String message = scanner.next();
            //设置生产者发送消息为持久化（要求保存到磁盘上）
            channel.basicPublish("",QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes(StandardCharsets.UTF_8));
            System.out.println("生产者生成消息："+message);
        }

    }
}
